const http =require("http")
const url = require('url')

//引入事件类
const EventEmiter =require("events")
//实例化自定事件对象
let routeEvent =new EventEmiter()

let routes =require('./routes.js')
routes(routeEvent)

const server =http.createServer((req,res)=>{
    res.setHeader("content-type", "text/html;charset=utf-8");

    let urlobj=url.parse(req.url,true)
    let pathname =urlobj.pathname;
    routeEvent.emit(pathname,req,res)

// if (pathname == "/index") {
//         let data = fs.readFileSync("./views/index.html");
//         res.write(data)
//     } else if (pathname == "/product") {
//         let data = fs.readFileSync("./views/product.html");
//         res.write(data)
//     } else if (pathname == "/users") {
//         let data = fs.readFileSync("./views/users.html");
//         res.write(data);
//     }

//     res.end()

})

server.listen(9090)
